package com.meixiang.view.photoSelectActivity.util;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.IOException;


public class ImageItem implements Parcelable {
	public String imageId;
	public String thumbnailPath;
	public String imagePath;
	private Bitmap bitmap;
	public boolean isSelected = false;

	public ImageItem(String imageId, String thumbnailPath, String imagePath, Bitmap bitmap, boolean isSelected) {
		this.imageId = imageId;
		this.thumbnailPath = thumbnailPath;
		this.imagePath = imagePath;
		this.bitmap = bitmap;
		this.isSelected = isSelected;
	}

	public String getImageId() {
		return imageId;
	}
	public void setImageId(String imageId) {
		this.imageId = imageId;
	}
	public String getThumbnailPath() {
		return thumbnailPath;
	}
	public void setThumbnailPath(String thumbnailPath) {
		this.thumbnailPath = thumbnailPath;
	}
	public String getImagePath() {
		return imagePath;
	}
	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}
	public boolean isSelected() {
		return isSelected;
	}
	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}
	public Bitmap getBitmap() {		
		if(bitmap == null){
			try {
				bitmap = Bimp.revitionImageSize(imagePath);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return bitmap;
	}
	public void setBitmap(Bitmap bitmap) {
		this.bitmap = bitmap;
	}


	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(this.imageId);
		dest.writeString(this.thumbnailPath);
		dest.writeString(this.imagePath);
		dest.writeParcelable(this.bitmap, flags);
		dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
	}

	public ImageItem() {
	}

	protected ImageItem(Parcel in) {
		this.imageId = in.readString();
		this.thumbnailPath = in.readString();
		this.imagePath = in.readString();
		this.bitmap = in.readParcelable(Bitmap.class.getClassLoader());
		this.isSelected = in.readByte() != 0;
	}

	public static final Parcelable.Creator<ImageItem> CREATOR = new Parcelable.Creator<ImageItem>() {
		@Override
		public ImageItem createFromParcel(Parcel source) {
			return new ImageItem(source);
		}

		@Override
		public ImageItem[] newArray(int size) {
			return new ImageItem[size];
		}
	};

	@Override
	public String toString() {
		return "ImageItem{" +
				"imageId='" + imageId + '\'' +
				", thumbnailPath='" + thumbnailPath + '\'' +
				", imagePath='" + imagePath + '\'' +
				", bitmap=" + bitmap +
				", isSelected=" + isSelected +
				'}';
	}
}
